package com.mall.client.server.controller;

import com.mall.client.server.domain.Client;
import com.mall.client.server.domain.Coupon;
import com.mall.client.server.domain.CouponIdsAndUserId;
import com.mall.client.server.domain.Points;
import com.mall.client.server.domain.vo.ClientVo;
import com.mall.client.server.domain.vo.FreezeVo;
import com.mall.client.server.domain.vo.VipVo;
import com.mall.client.server.service.IClientService;
import com.mall.common.core.domain.Result;
import com.mall.common.core.web.controller.BaseController;
import com.mall.common.log.annotation.Log;
import com.mall.common.log.enums.BusinessType;
import com.mall.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * 客户Controller
 *
 * @author ruoyi
 * @date 2025-02-16
 */
@RestController
@RequestMapping("/client")
public class ClientController extends BaseController
{
    @Autowired
    private IClientService clientService;

    /**
     * 查询客户列表
     */
    @RequiresPermissions("system:client:list")
    @GetMapping("/list")
    public Result list(Client client)
    {
        startPage();
        List<ClientVo> list = clientService.selectClientList(client);
        return getDataTable(list);
    }

//    /**
//     * 导出客户列表
//     */
//    @RequiresPermissions("system:client:export")
//    @Log(title = "客户", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, Client client)
//    {
//        List<ClientVo> list = clientService.selectClientList(client);
//        ExcelUtil<ClientVo> util = new ExcelUtil<ClientVo>(Client.class);
//        util.exportExcel(response, list, "客户数据");
//    }

    /**
     * 获取客户详细信息
     */
    @RequiresPermissions("system:client:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Integer id)
    {
        return success(clientService.selectClientById(id));
    }

    /**
     * 新增客户
     */
//    @RequiresPermissions("system:client:add")
//    @Log(title = "客户", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody Client client)
    {
        return toAjax(clientService.insertClient(client));
    }

    /**
     * 修改客户
     */
    @RequiresPermissions("system:client:edit")
    @Log(title = "客户", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody Client client)
    {
        return toAjax(clientService.updateClient(client));
    }

    /**
     * 删除客户
     */
    @RequiresPermissions("system:client:remove")
    @Log(title = "客户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Integer[] ids)
    {
        return toAjax(clientService.deleteClientByIds(ids));
    }

    /**
     * 用户领取优惠券
     */
    @PostMapping("/addCoupons")
    public void userCouponAdd(@RequestBody CouponIdsAndUserId couponIdsAndUserId ) {
        clientService.userCouponAdd(couponIdsAndUserId);
    }

    /**
     * 打标签
     */
    @PostMapping("/addTag")
    public void addTag(@RequestBody Client client) {
        clientService.addTag(client);
    }

    /**
     * 更新积分
     */
    @PostMapping("updateCurrentPoints")
    public Result updateCurrentPoints(@RequestBody Points points){
        clientService.updateCurrentPoints(points);
        return Result.success();
    }

    /**
     * 优惠券列表
     */
    @GetMapping("/selectCouponList")
    public Result selectCouponList() {
        List<Coupon> list = clientService.selectCouponList();
        return Result.success(list);
    }

    /**
     * 设置会员等级
     */
    @PostMapping("/addVipToCustomer")
    public Result addVipToCustomer(@RequestBody VipVo vipVo){
        clientService.addVipToCustomer(vipVo);
        return Result.success();
    }

    /**
     * 领会员
     */
    @PostMapping("/addSvip")
    public Result addSvip(@RequestBody Client client){
        clientService.addSvip(client);
        return Result.success();
    }


    /**
     * 查询所有限制行为
     */
    @GetMapping("/selectFreezeAll")
    public Result selectFreezeAll(){
        List<FreezeVo> freezeVos = clientService.selectCmmFreezeAll();
        return Result.success(freezeVos);
    }

    /**
     * 冻结
     */
    @PostMapping("/addClientFreeze")
    public Result addClientFreeze(@RequestBody Client client){
        clientService.addClientFreeze(client);
        return Result.success();
    }
}
